package br.indt.framework.ui.common;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import br.indt.framework.log.MicrologWrapper;
import br.indt.framework.ui.ImageLoader;

public abstract class PopUpLoadingItem extends Widget {
	
	private static final MicrologWrapper log = MicrologWrapper.getLogger(PopUpLoadingItem.class);
	
	protected int ARC_W = 18;
	protected int ARC_H = 18;
	protected int ICON_W = 46;
	protected int ICON_H = 46;

	protected int ICON_X;
	protected int ICON_Y = 142+27;

	protected static final int HEIGHT_ITEM = 178; //129
	protected Image icons = null;
//	protected String noteTitle;
	protected String note;
	protected int moving = 29;

	protected MenuItemListener menuItemListener = null;
	protected MenuItem rskItem = null;

	protected Label lbNote = null;
	protected ObjectActionListener objectActionListener = null;

	public PopUpLoadingItem(String name) {
		super(name);

		lbNote = new Label("lbNote", null, false, 1, null);
		lbNote.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));

		try {
			initIcon();
			ICON_X = (Display.getInstance().getWidth()/2)-(ICON_W/2);

		} catch (Exception e) {
			//#ifdef LOGS
			log.error("err in Display.getInstance().getWidth() ou getContentHeight() :" + e);
			//#endif
		}

		calculateHeight();
	}

	public void setWidth(int width) {
		this.width = width;
		lbNote.setWidth(width);
		calculateHeight();
	}

	private void calculateHeight() {
		height = HEIGHT_ITEM;
	}

	public int getHeight() {
		return height;
	}

	public abstract void paint(Graphics g, int x, int y, int maxWidth, int maxHeight);

	public abstract void click(int x, int y) ;

	public abstract void pressFire();

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
		lbNote.setText(note);
	}

	public int getMoving() {
		return moving;
	}

	public void setMoving(int moving) {
		this.moving = moving;
	}

	public void setMenuItemListener(MenuItemListener menuItemListener) {
		this.menuItemListener = menuItemListener;
	}

	public void setRSKItem(MenuItem menuItem) {
		rskItem = menuItem;
	}
	public void setObjectActionListener(ObjectActionListener objectActionListener) {
		this.objectActionListener = objectActionListener;
	}
	
	public void initIcon() {
		icons = ImageLoader.load("/spinner_canvas_15fps_46x46.png");
	}
	
	public void toggleIcon() {
		icons = ImageLoader.load("/loading_02.png");
	}

}